import request from '../request'
import type { ApiResponse } from '../types'

export interface LayoutStyle {
  container?: string
  title?: string
  content?: string
}

export interface LayoutConfig {
  id: string
  type: 'banner' | 'flash-sale' | 'product-showcase' | 'product-grid' | 'product-carousel' | 'brands' | 'new-arrivals' | 'topics' | 'reviews' | 'user-activity'
  title: string
  showTitle: boolean
  categoryId?: number
  isVisible: boolean
  order: number
  gridCols?: number
  style?: LayoutStyle
}

export interface LayoutResponse extends ApiResponse {
  data: LayoutConfig[]
}

// Define BannerItem interface based on backend fields
export interface BannerItem {
  id: number
  description: string
  path: string
  pic: string
  type: number
}

export interface BrandItem {
  id: number
  brandID: number
  name: string
  url: string
}

export const getLayoutConfig = () => {
  return request.post<LayoutResponse>('/app/app/layout/list')
}

export const getBannerList = () => {
  return request.post<BannerItem[]>('/app/info/banner/list', {
    type: 2
  })
}

export const getBrandList = () => {
  return request.post<BrandItem[]>('/app/brand/info/list')
}
